<?php

namespace App\Models\Order;

use App\Http\Services\Api\V1\App\Product\OrderService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * Class OrderHistory
 * @property string date_added
 * @package App\Models\Order
 * @mixin Builder
 */
class OrderHistory extends Model
{
    protected $table = 'order_history';
    protected $guarded = [];

    protected $primaryKey = 'order_history_id';

    public $timestamps = false;

    protected $dates = ['date_added']; // TODO 返回的carbon类了

    /**
     * @param Order $order
     * @param $payment_code
     * @param $order_status_id
     * @throws \Exception
     */
    public static function addCodOrderHistory(Order $order, $payment_code, $order_status_id)
    {
        if ($payment_code === Extension::EXTENSION_PAYMENT_COD) {
            (new OrderService)->updateOrderStatus($order, $order_status_id);
        }
    }
}
